﻿@using ST = EmoneyWeiXinCommon.StringTools
@{
    ViewBag.Title = "MemuManager";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@*<script src="~/config.js"></script>
<script src="../ueditor/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="../ueditor/ueditor/ueditor.all.js" type="text/javascript"></script>
<link href="~/My97DatePicker/skin/WdatePicker.css" rel="stylesheet" />
<script src="~/My97DatePicker/WdatePicker.js"></script>

<link href="~/Models/css/colorbox.css" rel="stylesheet" />
<link href="~/Models/css/tree_themes/SimpleTree.css" rel="stylesheet" />
<script src="~/Scripts/SimpleTree.js"></script>
<script src="~/Scripts/jquery.colorbox.js"></script>*@


@*<script src="@ST.GetStaticFile("config.js")"></script>*@
<script src="@ST.GetStaticFile("ueditor/ueditor/ueditor.config.js")" type="text/javascript"></script>
<script src="@ST.GetStaticFile("ueditor/ueditor/ueditor.all.js")" type="text/javascript"></script>
<link href="@ST.GetStaticFile("My97DatePicker/skin/WdatePicker.css")" rel="stylesheet" />
<script src="@ST.GetStaticFile("My97DatePicker/WdatePicker.js")"></script>

<link href="@ST.GetStaticFile("Models/css/colorbox.css")" rel="stylesheet" />
<link href="@ST.GetStaticFile("Models/css/tree_themes/SimpleTree.css")" rel="stylesheet" />
<script src="@ST.GetStaticFile("Scripts/SimpleTree.js")"></script>
<script src="@ST.GetStaticFile("Scripts/jquery.colorbox.js")"></script>

<script type="text/javascript" charset="utf-8">
    // window.UEDITOR_HOME_URL = EDIT_HOME_URL;
    window.UEDITOR_HOME_URL = "@EmoneyWeiXinCommon.Config.EDIT_HOME_URL";
</script>

<div class="right">
    <input id="hidid" style="display: none" />
    <input id="hidParentID" style="display: none" />
    <input id="hidNewsReportID" style="display: none" />

    <h3>自定义菜单管理</h3>
    <!--manage-->
    <div class="manage">
        <!--manage_top-->
        <div class="manage_top">
            <ul class="manage_top_ul">
            </ul>
        </div>
        <!--manage_top end-->
        <p class="manage_line"></p>
        <!--manage_found-->
        <div class="manage_found">
            <div class="manage_found_top">
                <span>可创建最多3个一级菜单，每个一级菜单下可创建5个二级菜单。</span>
                @*<a href="#" class="manage_found_top_font">预览</a>*@
                <a id="btnPush">发布</a>
            </div>
            <div class="manage_found_box">
                <!--manage_found_A-->
                <dl class="manage_found_A">
                    <dt class="manage_found_left">
                        <ul id="dvList">
                        </ul>
                        <em class="manage_found_triangle"></em>
                    </dt>
                    <dd class="manage_found_right">
                        <div class="manage_register">
                            <p><span>菜单名称：</span><input type="text" id="txtTitle"></p>
                            <p>
                                <span>是否在微信菜单中显示：</span>
                                <input type="radio" id="isweixinMemuYes" name="isweixinMemuYes" checked="checked">
                                <label for="isweixinMemuYes">是</label>
                                <input type="radio" id="isweixinMemuNo" name="isweixinMemuYes">
                                <label for="isweixinMemuNO">否</label>
                            </p>
                        </div>
                        <div class="manage_register">
                            <p>
                                <span>菜单类型：</span>
                                @* <input type="text" id="drpMenuType">*@
                                <select id="drpMenuType">
                                    @{ 
                                        if (ViewBag.menutype != null)
                                        {
                                            var table = ViewBag.menutype;
                                            for (int i = 0; i < table.Rows.Count; i++)
                                            {
                                        <option value="@table.Rows[i]["id"]">@table.Rows[i]["menuTypeDes"]:@table.Rows[i]["menuTypeValue"]</option>
                                            }
                                        }
                                    }

                                </select>

                            </p>
                            <p><span>排序号：</span><input type="text" id="txtOrder"></p>
                        </div>

                        <div class="manage_register" id="divAction">
                            <div class="manage_register_p02">
                                <span>设置动作：</span>
                                <input type="radio" id="rdActionYes" name="rdAction"><label for="rdActionYes">是</label>
                                <input type="radio" id="rdActionNo" name="rdAction" checked="checked"><label for="rdActionNo">否</label>
                                <div id="divActionTypeYes">
                                    <input type="radio" id="rdActionTypeYes" name="rdActionType"><label for="rdActionTypeYes">发送消息 </label>
                                </div>
                                <div id="divActionTypeNo">
                                    <input type="radio" id="rdActionTypeNo" name="rdActionType" checked="checked"><label for="rdActionTypeNo">跳转到网页</label>
                                </div>
                            </div>
                        </div>
                        <div class="manage_register" id="divSendMsg">
                            <div class="manage_register_p03">
                                <span><i class="icon iconfont"></i>文本模式</span>
                                <span class="gray" id="divtwxx"><i class="icon iconfont"></i>图文模式</span>
                                @*<span>还可以输入<b> 600</b> 字</span>*@
                                <textarea class="manage_register_mass" id="txtSendMsg"></textarea>
                            </div>
                        </div>

                        <div class="manage_bottom">
                            <table border="0" cellpadding="0" cellspacing="0" width="100%" style="display: none" id="tableNewsReport">
                                <tr>
                                    <th><span>编号</span></th>
                                    <th><span>标题</span></th>
                                    <th><span>栏目</span></th>
                                    <th><span>发布时间</span></th>
                                </tr>
                                <tbody id="reportList">
                                </tbody>
                            </table>
                        </div>

                        <div class="manage_register" id="divLinkUrl">
                            <div class="manage_register">
                                <p>
                                    <span>链接地址：</span>
                                    <input type="text" id="txtLinkUrl">
                                </p>
                                <p>
                                    <span>路径是否鉴权：</span>
                                    <input type="radio" id="rdisJQshi" name="rdJianQuan"><label for="rdActionYes">是</label>
                                    <input type="radio" id="rdisJQfou" name="rdJianQuan" checked="checked"><label for="rdActionNo">否</label>
                                </p>
                            </div>
                        </div>
                        <div class="manage_register">
                            <p><span>菜单关键字：</span><input type="text" id="txtMenuKeyWord"></p>
                            <p><span>订阅关键字：</span><input type="text" id="txtSubscribeKeyWord"></p>
                        </div>
                        <div class="manage_register">
                            <p><span>是否主动推送：</span><input type="radio" id="rdPushYes" name="rdPush"><label for="rdPushYes">是</label><input type="radio" id="rdPushNo" name="rdPush" checked="checked"><label for="rdPushNo">否</label></p>
                            <p><span>栏目是否默认发布：</span><input type="radio" id="rdDefaultSendYes" name="rdDefaultSend"><label for="rdDefaultSendYes">是</label><input type="radio" id="rdDefaultSendNo" name="rdDefaultSend" checked="checked"><label for="rdDefaultSendNo">否</label></p>
                        </div>
                        <div class="manage_register" id="divSelectTime">
                            @* <div class="manage_register_p02">
                                <span>设置时间范围：</span>
                                <input type="text" class="manage_found_text" id="txtStartTime" onfocus="WdatePicker()">--
                                <input type="text" class="manage_found_text" id="txtEndTime" onfocus="WdatePicker()">
                            </div>*@


                            <div class="manage_register">
                                <p>
                                    <span>设置时间范围：</span>
                                    <input type="text" class="manage_register_text02" id="txtStartTime" onfocus="WdatePicker()">
                                    <span class="manage_register_font">至</span>
                                    <input type="text" class="manage_register_text02" id="txtEndTime" onfocus="WdatePicker()">
                                </p>
                            </div>




                        </div>
                        <div class="manage_register" id="divPushRate">
                            <div class="manage_register_p02">
                                <span>推送频率：</span>
                                <input type="radio" id="rdPushRateYes" name="rdPushRate" checked="checked"><label for="rdPushRateYes">每天</label>
                                <input type="radio" id="rdPushRateNo" name="rdPushRate"><label for="rdPushRateNo">每周</label>
                                <div id="divDayType">
                                    <input type="checkbox" id="cbDayType1" name="cbDayType"><label for="cbDayType1">周一</label>
                                    <input type="checkbox" id="cbDayType2" name="cbDayType"><label for="cbDayType2">周二</label>
                                    <input type="checkbox" id="cbDayType3" name="cbDayType"><label for="cbDayType3">周三</label>
                                    <input type="checkbox" id="cbDayType4" name="cbDayType"><label for="cbDayType4">周四</label>
                                    <input type="checkbox" id="cbDayType5" name="cbDayType"><label for="cbDayType5">周五</label>
                                    <input type="checkbox" id="cbDayType6" name="cbDayType"><label for="cbDayType6">周六</label>
                                    <input type="checkbox" id="cbDayType7" name="cbDayType"><label for="cbDayType7">周六</label>
                                </div>
                            </div>
                        </div>
                        <div class="manage_register" id="divPushTime">
                            <div class="manage_register_p02">
                                <span>推送时间点：</span>
                                <input type="text" class="manage_found_text" id="txtPushTime1">
                                <input type="text" class="manage_found_text" id="txtPushTime2">
                                <input type="text" class="manage_found_text" id="txtPushTime3">
                                <input type="text" class="manage_found_text" id="txtPushTime4">
                                <input type="text" class="manage_found_text" id="txtPushTime5">
                                <span class="red">※支持最多5个时间点</span>
                            </div>
                        </div>


                        <p class="manage_line02"></p>
                        <div class="manage_register manage_found_C">
                            <div class="manage_register_p">
                                <span>固定页头：</span>
                                @* <textarea class="manage_register_reply" style="height: 100px"></textarea>*@
                                <textarea class="manage_register_reply" id="txtHeaderContent" style="height: 100px;"></textarea>
                            </div>
                        </div>
                        <div class="manage_register">
                            <div class="manage_register_p">
                                <span>固定页脚：</span>
                                @*<textarea class="manage_register_reply" style="height: 100px"></textarea>*@
                                <textarea class="manage_register_reply" id="txtFootContent" style="height: 100px;"></textarea>
                            </div>
                        </div>
                        <p class="manage_add"><a id="btnSave" style='display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(2, 3, ViewBag.leftid))'>确认</a><a class="manage_add_font" id="btnCancel">取消</a></p>

                    </dd>
                </dl>

            </div>
        </div>
        <!--manage_found end-->
    </div>
    <!--manage end-->
</div>

<div style="width: 100%; height: 100%; display: none; position: absolute; top: 0px; left: 0px;" id="loadDiv">
    <div id="subLoadDiv">
        <img src="@Url.Content("~/Static/Image/load.gif")" />
    </div>
</div>

<script type="text/javascript">
    var editor1 = new UE.ui.Editor();
    var editor2 = new UE.ui.Editor();
    var weixinid = "";
    var pageIndex = 1;
    var pageSize = 10;
    var pageCount = 1;
    var totalCount = 0;
    var newsid = "";
    $(document).ready(function () {
        editor1.render("txtHeaderContent");
        editor2.render("txtFootContent");
        createMemu();
        hidPageItem();
        //保存菜单
        $("#btnSave").click(function () {
            if (ischeck()) {
                var id = $("#hidid").val();
                var hidParentID = $("#hidParentID").val();
                var txtTitle = $("#txtTitle").val();
                var isweixinMemu = $("#isweixinMemuYes").attr("checked") == "checked" ? "1" : "0";
                var rdValid = "1";
                var drpMenuType = $("#drpMenuType").val();
                var txtOrder = $("#txtOrder").val();
                var txtMenuKeyWord = $("#txtMenuKeyWord").val();
                var txtSubscribeKeyWord = $("#txtSubscribeKeyWord").val();
                var rdPush = $("#rdPushYes").attr("checked") == "checked" ? "1" : "0";
                var rdDefaultSend = $("#rdDefaultSendYes").attr("checked") == "checked" ? "1" : "0";
                var rdPushRate = $("#rdPushRateYes").attr("checked") == "checked" ? "1" : "0";;
                var cbDayType1 = $("#cbDayType1").attr("checked") == "checked" ? "1" : "0";
                var cbDayType2 = $("#cbDayType2").attr("checked") == "checked" ? "2" : "0";
                var cbDayType3 = $("#cbDayType3").attr("checked") == "checked" ? "3" : "0";
                var cbDayType4 = $("#cbDayType4").attr("checked") == "checked" ? "4" : "0";
                var cbDayType5 = $("#cbDayType5").attr("checked") == "checked" ? "5" : "0";
                var cbDayType6 = $("#cbDayType6").attr("checked") == "checked" ? "6" : "0";
                var cbDayType7 = $("#cbDayType7").attr("checked") == "checked" ? "7" : "0";
                var cbDayType = cbDayType1 + "," + cbDayType2 + "," + cbDayType3 + "," + cbDayType4 + "," + cbDayType5 + "," + cbDayType6 + "," + cbDayType7;
                var txtPushTime1 = $("#txtPushTime1").val();
                var txtPushTime2 = $("#txtPushTime2").val();
                var txtPushTime3 = $("#txtPushTime3").val();
                var txtPushTime4 = $("#txtPushTime4").val();
                var txtPushTime5 = $("#txtPushTime5").val();
                var txtPushTime = txtPushTime1 + "," + txtPushTime2 + "," + txtPushTime3 + "," + txtPushTime4 + "," + txtPushTime5;
                var txtStartTime = $("#txtStartTime").val();
                var txtEndTime = $("#txtEndTime").val();
                var rdAction = $("#rdActionYes").attr("checked") == "checked" ? "1" : "0";
                var rdActionType = $("#rdActionTypeYes").attr("checked") == "checked" ? "1" : "0";
                var txtSendMsg = $("#txtSendMsg").val();
                var txtHeaderContent = editor1.getContent();
                var txtFootContent = editor2.getContent();
                var txtLinkUrl = $("#txtLinkUrl").val();
                var isJianQuan = $("#rdisJQshi").attr("checked") == "checked" ? "1" : "0";
                if (id > 0) {
                    operate("2", id,
                        hidParentID,
                        txtTitle,
                        rdValid,
                        drpMenuType,
                        txtOrder,
                        txtMenuKeyWord,
                        txtSubscribeKeyWord,
                        rdPush,
                        rdDefaultSend,
                        rdPushRate,
                        cbDayType,
                        txtPushTime,
                        txtStartTime,
                        txtEndTime,
                        rdAction,
                        rdActionType,
                        txtSendMsg,
                        txtLinkUrl,
                        txtHeaderContent,
                        txtFootContent, newsid, isweixinMemu, isJianQuan);
                }
                else {
                    operate("1", "0",
                        hidParentID,
                        txtTitle,
                        rdValid,
                        drpMenuType,
                        txtOrder,
                        txtMenuKeyWord,
                        txtSubscribeKeyWord,
                        rdPush,
                        rdDefaultSend,
                        rdPushRate,
                        cbDayType,
                        txtPushTime,
                        txtStartTime,
                        txtEndTime,
                        rdAction,
                        rdActionType,
                        txtSendMsg,
                        txtLinkUrl,
                        txtHeaderContent,
                        txtFootContent, newsid, isweixinMemu, isJianQuan);
                }
            }
        });
        //更新菜单到微信操作
        $("#btnPush").click(function () {
            $.ajax({
                type: "POST",
                url: "@ST.GetTrendsFile("Menu/UpdateWXMenu")" + "?random=" + Math.random(),
                async: true,
                data: { weixinid: weixinid },
                beforeSend: function () {
                    showLoading();
                },
                complete: function () {
                    hideLoading();
                },
                success: function (result) {
                    if (result == "1") {
                        alert("更新成功。");
                    }
                    else {
                        alert("更新失败。");
                    }
                }
            })
        });
        //取消操作
        $("#btnCancel").click(function () {
            reseting();
        });
        //是否主动推送
        $("input[name='rdPush']").each(function () {
            $(this).change(function () {
                hidPageItem();
            });
        });
        //每天每周
        $("input[name='rdPushRate']").each(function () {
            $(this).change(function () {
                hidPageItem();
            });
        });
        //设置动作
        $("input[name='rdAction']").each(function () {
            $(this).change(function () {
                hidPageItem();
            });
        });
        //发送消息，跳转网页
        $("input[name='rdActionType']").each(function () {
            $(this).change(function () {
                hidPageItem();
            });
        });
    });
    function getContentMemu() {
        $(".manage_top_ul .manage_top_A").each(function () {
            weixinid = $(this).attr("typeid");
        })
        if (weixinid > 0) {
            gotoPage();
            $('#divtwxx').colorbox({ href: "@ST.GetTrendsFile("Report/NewsReportListSelected")?weixinid=" + weixinid, title: false, iframe: true, width: "95%", height: "95%" });
        }
    }
    //创建labs
    function createMemu() {
        $.ajax(
            {
                type: "get",
                url: "@ST.GetTrendsFile("BaseConfiguration/WeixinUserMemu")" + "?random=" + Math.random(),
                async: true,
                data: { weixinid: "@ViewBag.weixinid" },
                dataType: "html",
                success: function (result) {
                    $(".manage_top_ul").html(result);
                    $(".manage_top_ul li").click(function () {
                        $(".manage_top_ul li").removeClass("manage_top_A");
                        $(this).addClass("manage_top_A");
                        reseting();
                        getContentMemu();
                    })
                    getContentMemu();
                }
            }
        )
        }
        function ischeck() {
            var title = $("#txtTitle").val();
            if (title == "") {
                alert("菜单名称不能空，请重新输入！");
                $("#txtTitle").focus();
                return false;
            }
            var menuKeyWord = $("#txtMenuKeyWord").val();
            if (menuKeyWord == "") {
                alert("菜单关键字不能空，请重新输入！");
                $("#txtMenuKeyWord").focus();
                return false;
            }
            return true;
        }
        //设置隐藏项
        function hidPageItem() {
            //设置动作
            if ($("#rdActionYes").attr("checked") == "checked") {
                $("#divActionTypeYes").css("display", "");
                $("#divActionTypeNo").css("display", "");

                if ($("#rdActionTypeYes").attr("checked") == "checked") {//发送消息
                    $("#divSendMsg").css("display", "");
                    $("#divLinkUrl").css("display", "none");
                }
                else {
                    $("#divSendMsg").css("display", "none");
                    $("#divLinkUrl").css("display", "");
                }
            }
            else {
                $("#divActionTypeYes").css("display", "none");
                $("#divActionTypeNo").css("display", "none");
                $("#divSendMsg").css("display", "none");
                $("#divLinkUrl").css("display", "none");
            }
            //是否主动推送
            if ($("#rdPushYes").attr("checked") == "checked") {
                $("#divSelectTime").css("display", "");
                $("#divPushRate").css("display", "");
                $("#divPushTime").css("display", "");
                $("#divAction").css("display", "");
                if ($("#rdPushRateNo").attr("checked") == "checked") {//每周
                    $("#divDayType").css("display", "");
                }
                else {
                    $("#divDayType").css("display", "none");
                }
            }
            else {
                $("#divSelectTime").css("display", "none");
                $("#divPushRate").css("display", "none");
                $("#divPushTime").css("display", "none");
                //$("#divAction").css("display", "none");
                //$("#divLinkUrl").css("display", "none");
                //$("#divSendMsg").css("display", "none");
            }
        }

        var ajaxdata = {};
        function gotoPage() {
            ajaxdata["weixinid"] = weixinid;
            ajaxdata["pindex"] = pageIndex;
            ajaxdata["psize"] = pageSize;
            $.ajax({
                url: "@ST.GetTrendsFile("Menu/GetMenuParentAndChildren")" + "?random=" + Math.random(),
                type: "POST",
                async: true,
                data: ajaxdata,
                beforeSend: function () {
                    //showLoading();
                },
                complete: function () {
                    //iddenLoading();
                },
                success: function (result) {
                    if (result != "" && result != null && result != undefined) {

                        var pd = result.p;
                        var cd = result.c;
                        var html = "";
                        if (pd != "" && pd != null && pd != undefined) {
                            for (var i = 0; i < pd.length; i++) {
                                html += '<li><span>' + pd[i]["title"] + '</span>';
                                html += '<i class="icon iconfont" onclick="DelMenu(' + pd[i]["id"] + ')" >&#xe604;</i>';//添加子菜单
                                html += '<i class="icon iconfont" onclick="Selected(' + pd[i]["id"] + ')">&#xe602;</i>';//编辑父菜单
                                html += '<i class="icon iconfont" onclick="AddMenu(' + pd[i]["id"] + ')">&#xe605;</i></li>';//删除父菜单
                                if (cd != "" && cd != null && cd != undefined) {
                                    for (var j = 0; j < cd.length; j++) {
                                        if (cd[j]["hisId"] == pd[i]["id"]) {
                                            html += '<li><span class="icon iconfont" >&#xe607;</span>';
                                            html += '<span>' + cd[j]["title"] + '</span>';
                                            html += '<i class="icon iconfont"  onclick="DelMenu(' + cd[j]["id"] + ')"  style="display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(3, ViewBag.leftid))">&#xe604;</i> ';//编辑子菜单
                                            html += '<i class="icon iconfont" onclick="Selected(' + cd[j]["id"] + ')"  style="display:@(new EmoneyWeiXin.Controllers.BaseConfigurationController().DisplayOperate(4, ViewBag.leftid))">&#xe602;</i>';//删除子菜单
                                            html += '</li>';
                                        }
                                    }
                                }
                            }
                        }
                        html += '';
                        $("#dvList").html(html);
                    }
                    else {
                        $("#dvList").html("没有查询到相关数据！");
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(errorThrown);
                },
                dataType: "json",

            });
        }
        //编辑操作
        function operate(op, id,
                            hidParentID,
                            txtTitle,
                            rdValid,
                            drpMenuType,
                            txtOrder,
                            txtMenuKeyWord,
                            txtSubscribeKeyWord,
                            rdPush,
                            rdDefaultSend,
                            rdPushRate,
                            cbDayType,
                            txtPushTime,
                            txtStartTime,
                            txtEndTime,
                            rdAction,
                            rdActionType,
                            txtSendMsg,
                            txtLinkUrl,
                            txtHeaderContent,
                            txtFootContent, newsreportids, isweixinMemu, isJianQuan) {
            $.ajax({
                url: "@ST.GetTrendsFile("Menu/UpdateMenu")" + "?random=" + Math.random(),
                type: "POST",
                async: true,
                data: {
                    op: op, id: id, txtParentID: hidParentID,
                    txtTitle: txtTitle,
                    rdValid: rdValid,
                    drpMenuType: drpMenuType,
                    txtOrder: txtOrder,
                    txtMenuKeyWord: txtMenuKeyWord,
                    txtSubscribeKeyWord: txtSubscribeKeyWord,
                    rdPush: rdPush,
                    rdDefaultSend: rdDefaultSend,
                    rdPushRate: rdPushRate,
                    cbDayType: cbDayType,
                    txtPushTime: txtPushTime,
                    txtStartTime: txtStartTime,
                    txtEndTime: txtEndTime,
                    rdAction: rdAction,
                    rdActionType: rdActionType,
                    txtSendMsg: txtSendMsg,
                    txtLinkUrl: txtLinkUrl,
                    txtHeaderContent: txtHeaderContent,
                    txtFootContent: txtFootContent,
                    weixinid: weixinid,
                    newsreportids: newsreportids,
                    isweixinMemu: isweixinMemu,
                    isJianQuan: isJianQuan
                },
                beforeSend: function () {
                    //showLoading();
                },
                complete: function () {
                    // hiddenLoading();
                },
                success: function (data) {
                    if (data == "1") {
                        gotoPage();
                        reseting();
                        alert("操作成功!");

                    } else alert(data);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(errorThrown);
                }
            });
        }
        //添加菜单操作
        function AddMenu(parentid) {
            if (parentid > 0) {//表示添加子菜单，父菜单id=parentid
                //清空页面设置
                reseting();
                $("#hidParentID").val(parentid);
            }
            else {
                //清空页面设置
                reseting();
            }
        }
        //删除菜单某一项
        function DelMenu(id) {
            if (confirm("确认删除？")) {
                $.ajax({
                    url: "@ST.GetTrendsFile("Menu/DeleteMenu")" + "?random=" + Math.random(),
                    type: "POST",
                    async: true,
                    data: {
                        id: id
                    },
                    beforeSend: function () {
                        //showLoading();
                    },
                    complete: function () {
                        // hiddenLoading();
                    },
                    success: function (data) {
                        if (data == "1") {
                            gotoPage();
                            reseting();
                            alert("操作成功!");

                        } else alert(data);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        //alert(errorThrown);
                    }
                });
            }
        }
        //选择菜单某一项，显示在页面上
        function Selected(id) {
            $.ajax({
                url: "@ST.GetTrendsFile("Menu/GetMenuByID")" + "?random=" + Math.random(),
                type: "GET",
                async: true,
                data: { id: id },
                beforeSend: function () {
                    //showLoading();
                },
                complete: function () {
                    //iddenLoading();
                },
                dataType: "json",
                success: function (result) {
                    if (result != "" && result != null && result != undefined) {
                        //var dd = eval("[" + data + "]");

                        //var arryData = result.split('~');
                        //var d = arryData[0];
                        //d = eval("[" + d + "]");
                        //var dd = d[0];
                        //var d1 = arryData[1];
                        var dd = result.obj;
                        var d1 = result.obj2;
                        if (dd != "" && dd != null && dd != undefined) {
                            var d = dd;
                            var id = d["id"];
                            var hidParentID = d["hisId"];
                            var txtTitle = d["title"];
                            var rdValid = d["isvalid"];
                            var drpMenuType = d["mtype"];
                            var txtOrder = d["sort"];
                            var txtMenuKeyWord = d["everyKey"];
                            var txtSubscribeKeyWord = d["Keyword"];
                            var rdPush = d["isThread"];
                            var rdDefaultSend = d["PubStatus"];
                            var rdPushRate = d["DayType"];
                            var cbDayType1 = "";
                            var cbDayType2 = "";
                            var cbDayType3 = "";
                            var cbDayType4 = "";
                            var cbDayType5 = "";
                            var cbDayType6 = "";
                            var cbDayType7 = "";
                            var txtPushTime1 = "";
                            var txtPushTime2 = "";
                            var txtPushTime3 = "";
                            var txtPushTime4 = "";
                            var txtPushTime5 = "";
                            if (rdPushRate == "1") {//表示每天
                                var jgtiemStr = d["jgtimeStr"];
                                if (jgtiemStr != null && jgtiemStr != "" && jgtiemStr != undefined) {
                                    var arrJgTimeStr = jgtiemStr.split(",");
                                    txtPushTime1 = arrJgTimeStr[0];
                                    txtPushTime2 = arrJgTimeStr[1];
                                    txtPushTime3 = arrJgTimeStr[2];
                                    txtPushTime4 = arrJgTimeStr[3];
                                    txtPushTime5 = arrJgTimeStr[4];
                                }
                            }
                            else {//表示每周
                                var thday = d["thday"];
                                if (thday != null && thday != "" && thday != undefined) {
                                    var arrThDay = thday.split(',');
                                    cbDayType1 = arrThDay[0];
                                    cbDayType2 = arrThDay[1];
                                    cbDayType3 = arrThDay[2];
                                    cbDayType4 = arrThDay[3];
                                    cbDayType5 = arrThDay[4];
                                    cbDayType6 = arrThDay[5];
                                    cbDayType7 = arrThDay[6];
                                }
                            }
                            var isweixinMemu = d["isweixinMemu"];
                            var txtStartTime = d["starttime"];
                            var txtEndTime = d["endtime"];
                            var rdAction = d["isAction"];
                            var rdActionType = d["isSend"];
                            var txtSendMsg = d["sendMsg"];
                            var txtLinkUrl = d["linkUrl"];
                            var txtHeaderContent = d["contentym"];
                            var txtFootContent = d["contentyj"];
                            var isJianQuan = d["isJianQuan"];
                            //var newsreportid = d["newsid"];
                            SettingPageValue(id, hidParentID,
                             txtTitle,
                             rdValid,
                             drpMenuType,
                             txtOrder,
                             txtMenuKeyWord,
                             txtSubscribeKeyWord,
                             rdPush,
                             rdDefaultSend,
                             rdPushRate,
                             cbDayType1,
                             cbDayType2,
                             cbDayType3,
                             cbDayType4,
                             cbDayType5,
                             cbDayType6,
                             cbDayType7,
                             txtPushTime1,
                             txtPushTime2,
                             txtPushTime3,
                             txtPushTime4,
                             txtPushTime5,
                             txtStartTime,
                             txtEndTime,
                             rdAction,
                             rdActionType,
                             txtSendMsg,
                             txtLinkUrl,
                             txtHeaderContent,
                             txtFootContent, d1, isweixinMemu,isJianQuan)
                        }
                        hidPageItem();
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    //alert(errorThrown);
                }
            });
        }
        //重置
        function reseting() {
            $("#hidid").val("0");
            $("#hidParentID").val("0");
            $("#txtTitle").val("");
            //$("#rdValidYes").attr("checked", true);
            $("#drpMenuType").val("");
            $("#txtOrder").val("");
            $("#txtMenuKeyWord").val("");
            $("#txtSubscribeKeyWord").val("");
            $("#rdPushNo").attr("checked", true);
            $("#rdDefaultSendNo").attr("checked", true);
            $("#rdPushRateNo").attr("checked", true);
            $("#cbDayType1").attr("checked", false);
            $("#cbDayType2").attr("checked", false);
            $("#cbDayType3").attr("checked", false);
            $("#cbDayType4").attr("checked", false);
            $("#cbDayType5").attr("checked", false);
            $("#cbDayType6").attr("checked", false);
            $("#cbDayType7").attr("checked", false);
            $("#txtPushTime1").val("");
            $("#txtPushTime2").val("");
            $("#txtPushTime3").val("");
            $("#txtPushTime4").val("");
            $("#txtPushTime5").val("");
            $("#txtStartTime").val("");
            $("#txtEndTime").val("");
            $("#rdActionNo").attr("checked", true);
            $("#rdActionTypeNo").attr("checked", true);
            $("#txtSendMsg").val("");
            $("#txtLinkUrl").val("");
            editor1.setContent("");
            editor2.setContent("");
            hidPageItem();

            $("#tableNewsReport").css("display", "none");
            $("#reportList").html("");
            newsid = "";

        }
        //选择行
        function SettingPageValue(id, hidParentID,
            txtTitle,
            rdValid,
            drpMenuType,
            txtOrder,
            txtMenuKeyWord,
            txtSubscribeKeyWord,
            rdPush,
            rdDefaultSend,
            rdPushRate,
            cbDayType1,
            cbDayType2,
            cbDayType3,
            cbDayType4,
            cbDayType5,
            cbDayType6,
            cbDayType7,
            txtPushTime1,
            txtPushTime2,
            txtPushTime3,
            txtPushTime4,
            txtPushTime5,
            txtStartTime,
            txtEndTime,
            rdAction,
            rdActionType,
            txtSendMsg,
            txtLinkUrl,
            txtHeaderContent,
            txtFootContent, d1, isweixinMemu, isjianQuan) {
            $("#hidid").val(id);
            $("#hidParentID").val(hidParentID);
            $("#txtTitle").val(txtTitle);
            //if(rdValid=="1")
            //    $("#rdValidYes").attr("checked", true);
            //else
            //    $("#rdValidNo").attr("checked", true);
            $("#drpMenuType").val(drpMenuType);
            $("#txtOrder").val(txtOrder);
            $("#txtMenuKeyWord").val(txtMenuKeyWord);
            $("#txtSubscribeKeyWord").val(txtSubscribeKeyWord);
            if (rdPush == "1")
                $("#rdPushYes").attr("checked", true);
            else
                $("#rdPushNo").attr("checked", true);
            if (rdDefaultSend == "1") {
                $("#rdDefaultSendYes").attr("checked", true);
            }
            else {
                $("#rdDefaultSendNo").attr("checked", true);
            }
            if (rdPushRate == "1") {
                $("#rdPushRateYes").attr("checked", true);
            }
            else {
                $("#rdPushRateNo").attr("checked", true);
            }

            if (isweixinMemu == "1") {
                $("#isweixinMemuYes").attr("checked", true);
            }
            else {
                $("#isweixinMemuNo").attr("checked", true);
            }

            $("#cbDayType1").attr("checked", cbDayType1 == "1");
            $("#cbDayType2").attr("checked", cbDayType2 == "2");
            $("#cbDayType3").attr("checked", cbDayType3 == "3");
            $("#cbDayType4").attr("checked", cbDayType4 == "4");
            $("#cbDayType5").attr("checked", cbDayType5 == "5");
            $("#cbDayType6").attr("checked", cbDayType6 == "6");
            $("#cbDayType7").attr("checked", cbDayType7 == "7");
            $("#txtPushTime1").val(txtPushTime1);
            $("#txtPushTime2").val(txtPushTime2);
            $("#txtPushTime3").val(txtPushTime3);
            $("#txtPushTime4").val(txtPushTime4);
            $("#txtPushTime5").val(txtPushTime5);
            $("#txtStartTime").val(txtStartTime);
            $("#txtEndTime").val(txtEndTime);
            if (rdAction == "1") {
                $("#rdActionYes").attr("checked", true);
            }
            else {
                $("#rdActionNo").attr("checked", true);
            }
            if (rdActionType == "1") {
                $("#rdActionTypeYes").attr("checked", true);
            }
            else {
                $("#rdActionTypeNo").attr("checked", true);
            }
            if (isjianQuan == "1") {
                $("#rdisJQshi").attr("checked", true);
            } else {
                $("#rdisJQfou").attr("checked", true);
            }
            $("#txtSendMsg").val(txtSendMsg);
            $("#txtLinkUrl").val(txtLinkUrl);
            editor1.setContent(txtHeaderContent);
            editor2.setContent(txtFootContent);
            //显示图文列表
            d1 = eval(d1);
            $("#reportList").html("");
            $("#tableNewsReport").css("display", "none");
            if (d1 != null && d1 != undefined && d1 != "" && d1.length > 0) {
                $("#tableNewsReport").css("display", "");
                getTWList(d1);
            }
        }
        function getTxtTd(s) {
            return '<td><span>' + s + '</span></td>';
        }
        //查询图文资讯列表
        function getTWList(d) {
            var ids = "";
            var html = "";
            for (var i = 0; i < d.length; i++) {
                html += "<tr>";
                html += getTxtTd(d[i]["ID"]) + getTxtTd(d[i]["title"]) + getTxtTd(d[i]["menuname"]);
                html += getTxtTd(getFormatDate(new Date(d[i]["updatetime"]), "yyyy-mm-dd", 0));
                html += '</tr>';
                ids += d[i]["ID"] + '^';
            }
            newsid = ids.substring(0, ids.length - 1);
            $("#reportList").html(html);
        }
        //显示图文资讯列表
        function getTWList2(newsreportid, titles, menunames, updatetimes) {
            var html = "";
            newsreportid = newsreportid.substring(1, newsreportid.length - 1);
            titles = titles.substring(0, titles.length - 1);
            menunames = menunames.substring(0, menunames.length - 1);
            updatetimes = updatetimes.substring(0, updatetimes.length - 1);
            var arryNewsReportIDs = newsreportid.split('^');
            var arryTitles = titles.split('^');
            var arryMenuNames = menunames.split('^');
            var arryUpdateTimes = updatetimes.split('^');
            for (var i = 0; i < arryNewsReportIDs.length; i++) {
                html += "<tr>";
                html += getTxtTd(arryNewsReportIDs[i]) + getTxtTd(arryTitles[i]) + getTxtTd(arryMenuNames[i]);
                html += getTxtTd(getFormatDate(new Date(arryUpdateTimes[i]), "yyyy-mm-dd", 0));
                html += '</tr>';
            }
            $("#reportList").html(html);
        }
        //
        //function UpdatePD(newsreportid) {
        //    $('#divtwxx').colorbox.close();
        //    newsid = newsreportid;
        //}
        function UpdatePD(newsreportids, titles, menunames, updatetimes) {
            $('#divtwxx').colorbox.close();
            newsid = newsreportids;
            if (newsid != "") {
                $("#tableNewsReport").css("display", "");
                //显示图文列表
                getTWList2(newsreportids, titles, menunames, updatetimes);
            }
        }

        function showLoading() {
            var margintop = (document.documentElement.clientHeight) / 2 - 20;
            var marginleft = (document.documentElement.clientWidth) / 2 - 20;
            $("#subLoadDiv").css({ "margin-top": margintop, "margin-left": marginleft });
            $("#loadDiv").show();
        }

        function hideLoading() {
            $("#loadDiv").hide();
        }

</script>



